﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using Common.Utilities;
using Common.Utilities.Dispatcher;

namespace Workflows.Components.TextMining.TextScraping
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class PdfDocFullTextOutput:ResultBase
    {
        #region props
        private int _TotalFileProcessed;
        /// <summary></summary>
        public int TotalFileProcessed
        {
            get
            {
                return this._TotalFileProcessed;
            }
            set
            {
                this._TotalFileProcessed = value;
            }
        }

        private int _TotalFullTextExtracted;
        /// <summary></summary>
        public int TotalFullTextExtracted
        {
            get
            {
                return this._TotalFullTextExtracted;
            }
            set
            {
                this._TotalFullTextExtracted = value;
            }
        }
        #endregion

        /// <summary>
        /// 
        /// </summary>
        public PdfDocFullTextOutput():base(Guid.Empty,Guid.Empty)
        {
            this._TotalFullTextExtracted = 0;
            this._TotalFileProcessed = 0;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="componentID"></param>
        /// <param name="jobTicketID"></param>
        /// <param name="fileProcessed"></param>
        /// <param name="contentExtracted"></param>
        public PdfDocFullTextOutput(Guid componentID, Guid jobTicketID,
            int fileProcessed, int contentExtracted) 
            : base(componentID, jobTicketID)
        {
            this._TotalFileProcessed = fileProcessed;
            this._TotalFullTextExtracted = contentExtracted;
        }

        #region Overrides of ResultBase

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xDoc"></param>
        /// <param name="parentNode"></param>
        /// <returns></returns>
        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = XmlDataUtil.AddElement(ref xDoc, parentNode, "Output");
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "Type", this.GetType().FullName);
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "WorkerID", this.OwnerWorkerInstanceID.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FinishTime", this.FinishTime.ToString());

            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FileProcessed", this.TotalFileProcessed.ToString());
            XmlDataUtil.UpdateAttribute(ref xDoc, xNode, "FullTextExtracted", this.TotalFullTextExtracted.ToString());

            return xNode;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="xNode"></param>
        /// <returns></returns>
        public override ResultBase Instantiate(XmlNode xNode)
        {
            if (xNode.Attributes.GetNamedItem("Type").Value == this.GetType().FullName)
            {
                PdfDocFullTextOutput output = new PdfDocFullTextOutput();
                output.OwnerWorkerInstanceID = new Guid(xNode.Attributes.GetNamedItem("WorkerID").Value);
                output.FinishTime = DateTime.Parse(xNode.Attributes.GetNamedItem("FinishTime").Value);

                output.TotalFileProcessed = int.Parse(XmlDataUtil.GetAttributeValue(xNode, "FileProcessed", "0"));
                output.TotalFullTextExtracted =
                    int.Parse(XmlDataUtil.GetAttributeValue(xNode, "FullTextExtracted", "0"));

                return output;
            }
            else
            {
                throw new Exception("Unable to instantiate output: invalid type specified in xml node");
            }
        }

        #endregion
    }
}
